<template>
	<view class="one">
		<view class="nav">
			<view class="imga">
				<image src="/static/组 6@2x.png"></image>
				
			</view>
			<view class="bd">
				<view class="title">车辆类型</view>
				<view >
					<picker class="tit"  @change="bindPickerChange" :value="index" :range="array" >
						<view class="titone">{{ selectedValue }}</view>
					</picker>
					
				</view>
			</view>
			<view class="bd">
				<view class="title">车量型号</view>
				<view >
					<picker class="tit"  @change="bindPickerChangeone" :value="indexone" :range="arrayone" >
						<view class="titone">{{ selectedValueone }}</view>
					</picker>
					
				</view>
			</view>
			<view class="bd">
				<view class="title">车牌号码</view>
				<view >
					<input class="tit" type="text"   v-model="changeValue" placeholder="请输入您的车牌号码" placeholder-class="pcs" />
					
				</view>
			</view>
			
			<view class="bd">
				<view class="title">车主姓名</view>
				<view >
					<input class="tit" type="text"  @input="bindname" v-model="name" placeholder="请输入您的车主姓名" placeholder-class="pcs" />
					
				</view>
			</view>
			<view class="bd">
				<view class="title">电话号码</view>
				<view >
					<input class="tit" type="number"   v-model="phone" placeholder="请输入您的电话号码" placeholder-class="pcs" />
					
				</view>
			</view>
			<view class="bd">
				<view class="title">照片</view>
				<view class="upload-box">
					<view class="upload-item" v-if="imageUrl">
						<image :src="imageUrl" mode="aspectFill" class="preview-image"/>
						<view class="delete-btn" @tap="deleteImage">×</view>
					</view>
					<view class="upload-btn" v-else @tap="chooseImage">
						<text class="plus">+</text>
						<text class="upload-text">上传照片</text>
					</view>
				</view>
			</view>
			<view class="bottom-btn">
				<button class="submit-btn" @tap="submitForm">添加车辆</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				index: -1,
				array: ['奥迪','小米suv'],
				indexone:-1,
				arrayone:['型号1','型号2'],
				changeValue:'',//车派号码输入框的数据绑定
				name:'',
				phone:'',
				imageUrl: '', // 存储上传的图片路径
			}
		},
		computed: {
			selectedValue() {
				return this.index === -1 ? '请选择' : this.array[this.index]
			},
			selectedValueone() {
				return this.indexone === -1 ? '请选择' : this.arrayone[this.indexone]
			}
		},
		methods: {
			 bindPickerChange: function(e) {
			            console.log('picker发送选择改变，携带值为', e.detail.value)
			            this.index = e.detail.value
						
			        },
					bindPickerChangeone: function(e) {
					           console.log('picker型号发送选择改变，携带值为', e.detail.value)
					           this.indexone = e.detail.value
											
					       },
				bindname(event){//获取输入框的值赋值
					this.name =  event.target.value
					console.log(event.target.value)
				},
				
				// 选择图片
				chooseImage() {
					uni.chooseImage({
						count: 1,
						sizeType: ['compressed'],
						sourceType: ['album', 'camera'],
						success: (res) => {
							this.imageUrl = res.tempFilePaths[0]
						}
					})
				},
				
				// 删除图片
				deleteImage() {
					this.imageUrl = ''
				},
				submitForm() {
					// 这里处理表单提交逻辑
					console.log('提交表单')
				}
		}
	}
</script>

<style>
page{
	background:#F7F7F7;
	}  
	.one{
		padding-top: 20rpx;
		height: 200rpx;
		background-color: #2D80F9;
	}
	.nav{
		width: 680rpx;
		background-color: white;
		height: 82vh;
		border-radius: 20rpx;
		margin: 0 auto;
	}
	.imga{
		padding: 20rpx 0;
		display: flex;
		justify-content: center;
		align-items: center;
	}
	.imga image{
		width: 400rpx;
		height: 220rpx;
		display: block;
		margin: 0 auto;
	}
			
		.bd{
			display: flex;
			margin-top: 30rpx;
			}
		
		.title{
			
			background-color: #4FA2FF;
			padding: 20rpx;
			font-size: 30rpx;
			border-radius: 50rpx;
			color: white;
			margin-left: 20rpx;
			width: 120rpx;
			height: 30rpx;
			line-height: 30rpx;
			text-align: center;
		}
		
		.tit{
			border-radius: 50rpx;
			border: 1rpx solid #DADADA;
			margin-left: 10rpx;
			height: 80rpx;
			width: 450rpx;
			padding-left: 20rpx;
		}
		.titone{
			margin-left: 40rpx;
			margin-top: 18rpx;
			color:#DADADA;
		}
		
		.pcs {
			margin-left: 36rpx;
		      color: #DADADA;
		       font-size: 28rpx;
		
				}

.upload-box {
	margin-left: 10rpx;
}

.upload-btn {
	width: 160rpx;
	height: 160rpx;
	border: 1px dashed #DADADA;
	border-radius: 12rpx;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	background-color: #FAFAFA;
}

.plus {
	font-size: 48rpx;
	color: #999;
	margin-bottom: 10rpx;
}

.upload-text {
	font-size: 24rpx;
	color: #999;
}

.upload-item {
	width: 160rpx;
	height: 160rpx;
	position: relative;
}

.preview-image {
	width: 100%;
	height: 100%;
	border-radius: 12rpx;
}

.delete-btn {
	position: absolute;
	top: -20rpx;
	right: -20rpx;
	width: 40rpx;
	height: 40rpx;
	background-color: rgba(0, 0, 0, 0.5);
	color: #fff;
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 24rpx;
}

.bottom-btn {
	position: fixed;
	bottom: 40rpx;
	left: 0;
	right: 0;
	padding: 0 40rpx;
	display: flex;
	justify-content: center;
}

.submit-btn {
	width: 600rpx;
	height: 80rpx;
	line-height: 80rpx;
	background-color: #2D80F9;
	color: #fff;
	border-radius: 40rpx;
	font-size: 32rpx;
	border: none;
	text-align: center;
}

/* 按钮点击效果 */
.submit-btn:active {
	opacity: 0.8;
}
</style>
